package lab03.test13;

import java.sql.*;

public class Test13 {
    public static void main(String[] args) {

        //3+1
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        String sql = "insert into t_students(real_name,age,gender,department,stu_no) values('chen',20,1,'信息','1234')";
        String sql1 = "delete from t_students where id=5";
        String sql2 = "select * from t_students";
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                    "root",
                    "12qwas"
            );

            //statement:查
            statement = connection.createStatement();

            //ResultSet:
            statement.execute(sql);
            statement.execute(sql1);
            resultSet = statement.executeQuery(sql2);
            while (resultSet.next()) {

                System.out.println(resultSet.getInt(1));
                System.out.println(resultSet.getString(2));
                System.out.println(resultSet.getString(3));
                System.out.println(resultSet.getInt(4));
                System.out.println(resultSet.getInt(5));
                System.out.println(resultSet.getString(6));

            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {

                statement.close();
                connection.close();

            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }

}
